<?php
class applySearchForm extends sfForm
{

  public function configure()
  {
  	parent::configure();
  	$formaterName = sfConfig::get('app_form_formatterName','app');
	$this->getWidgetSchema()->setFormFormatterName($formaterName);
  }	
	/*Set the possible saved searches than the user can apply*/
  public function setSearchDefCandidates($className){
  	$sfUser = sfContext::getInstance()->getUser();
	$userProfile = $sfUser->getUserProfile();
	if($userProfile){
			$table = Doctrine::getTable(get_class($userProfile));
			$identifier = $table->getIdentifier();
			$user_id = $userProfile->$identifier;
	}
	
	$q=DQ::create()
		    ->select('a.id, a.description as name')
			->from('filterdef a') 
			->orderBy('a.description');
	$q->andWhere('a.user_id = '.$user_id);
	$q->orWhere('a.public = 1');
	$q->whereParenWrap();
	/*Filtrar por la clase del filtro.*/
	$q->andWhere('a.filterclassname = ?',$className);
	
	 $this->setWidgets(array(
	 	'search' =>  new sfWidgetFormDoctrineChoice(
		 								array('model' => 'filterdef',
		 								//'method'=> 'get'.$descriptor,
		 								'query' => $q,
		 								'add_empty' => sfContext::getInstance()->getI18N()->__('Please select a value...')))
	 ));
	 $this->offsetGet('search')->getWidget()->setAttributes(array(
			'class' => 'combobox',
	 ));
	 $this->offsetGet('search')->getWidget()->setLabel(sfContext::getInstance()->getI18N()->__('Choose a filter to apply'));
  }
  
 }